package pjkanri.service;

import java.util.List;

import pjkanri.dao.DAOException;
import pjkanri.dao.ProjectUserDAO;

public class ProjectUserService {


//private Integer getMaxId() throws DAOException{
//		
//		Integer maxId = 0;
//		String sql = "SELECT Max(project_id) as max FROM project ";
//
//		DataSource ds = DataSourceFactory.getDataSource();
//
//		try (Connection conn = ds.getConnection();
//				Statement pstmt = conn.createStatement()) {
//
//			try (ResultSet rs = pstmt.executeQuery(sql)) {
//
//				if (rs.next()) {
//					if (rs.getString("max") == null ) return 0;
//					maxId = Integer.parseInt(rs.getString("max"));
//				}
//			}
//
//		} catch (SQLException e) {
//			throw new DAOException(e);
//		}
//		return maxId;
//	}
	
	
//	public void insert(Project project) throws DAOException {
//		Session session = HibernateUtil.getSessionFactory()
//				.getCurrentSession();
//		
//		project.setProject_id(getMaxId()+1);		
//		
//		System.out.println("Project : " + project );
//		session.save(project);
//}

//	public void update(Project prj) throws DAOException {
//		Session session = HibernateUtil.getSessionFactory()
//				.getCurrentSession();
//		
//		Project project = (Project) session.get(Project.class, prj.getProject_id());
//		
//		project.setProject_name(prj.getProject_name());
//		project.setProject_description(prj.getProject_description());
//		
//}
	
	

	public static void insert(ProjectUserDAO prj) throws DAOException {
		ProjectUserDAO prjdao = new ProjectUserDAO();
		prjdao.insert(prj);
	}

	public static void update(ProjectUserDAO prj) throws DAOException {
		ProjectUserDAO prjdao = new ProjectUserDAO();
		prjdao.update(prj);
	}

	public static List<ProjectUserDAO> getProjectList() throws DAOException {
		ProjectUserDAO prjdao = new ProjectUserDAO();
		return prjdao.getProjectList();
	}

}